package com.spark.core.transformation

import org.apache.spark.rdd.RDD
import org.apache.spark.{SparkConf, SparkContext}

/**
 * rightOuterJoin
 * (K,V)格式的RDD和(K,W)格式的RDD 使用rightOuterJoin结合是以右边的RDD出现的key为主，得到（K,(Option(V)，W)）
 */
object Demo10_rightOuterJoin {
  def main(args: Array[String]): Unit = {
    val conf = new SparkConf()
    conf.setMaster("local")
    conf.setAppName("rightOuterJoin")
    val sc = new SparkContext(conf)
    sc.setLogLevel("error")


    val nameRDD = sc.parallelize(List[(String, String)](("zhangsan", "female"), ("zhangsan", "new"),
      ("lisi", "male"), ("wangwu", "female"), ("zhaoliu", "male")), 3)
    val scoreRDD = sc.parallelize(List[(String, Int)](("zhangsan", 18), ("zhangsan", 20),
      ("lisi", 19), ("wangwu", 20), ("tianqi", 25)), 2)

    val rightJoin: RDD[(String, (Option[String], Int))] = nameRDD.rightOuterJoin(scoreRDD)

    println(rightJoin.getNumPartitions)

    rightJoin.foreach(println)


  }
}
